#pragma once
#include <Windows.h>
#include "comm_type.h"
#include <QTcpSocket>
#include <QByteArray>
#include <QDebug>
#include <queue>
using namespace  std;
class MQ
{
public:
    MQ(void);
    ~MQ(void);
    int Recv(char *buf, int len);
    int Send(char *buf);
    int Connect(Payload *clientId, bool iscleansession = false, short keepalive = 60, Payload *user = NULL, Payload *pwd = NULL, Payload *willTopic = NULL, Payload *willMessage = NULL);
    int Subscribe(short packetId, char *topicName, int topiclen);
    int UnSubscribe(short packetId, char *topicName, int topiclen);
    int DisConnect();
    int PinReq();
private:
    int Send0(char *buf, int len);
    int Proc(char *buf, int len, int lenbyte = 1);
    int Publish();
    int PubRec();
    int PubRel();
    int PubComp();
    int SendMqtt(int type, char *buf, int len, int dup = 0, int qos = 0, int remain = 0);
private:
    queue<MMSG> msgqueue;
};

